package modele;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.Collection;
import java.util.HashSet;
import java.util.TreeSet;

public class DAO {

    public static Collection<Dep> getLesDeps() {

        try {
            Connection con = Connect.get();
            Statement req;
            Statement req2;

            req = con.createStatement();
            req2 = con.createStatement();
            ResultSet rs = req.executeQuery("Select distinct departement from medecin");

            Collection<Dep> d;
            d = new TreeSet<Dep>();
            while (rs.next()) {
                

                
                Dep dd = new Dep(rs.getString("departement"));
                d.add(dd);

            }
            return d;

        } catch (Exception e) {
            System.out.println("Erreur dans le programme");
            e.printStackTrace();
        }
        return null;

    }

    public static Collection<Med> getLesMeds() {
        try {
            Connection con = Connect.get();
            Statement req;
            req = con.createStatement();
            ResultSet rs = req.executeQuery("Select * from medecin");
            Collection<Med> m;
            m = new TreeSet<Med>();
            while (rs.next()) {

                Med mm = new Med(rs.getString("nom"), rs.getString("prenom"),
                        rs.getString("adresse"), rs.getString("tel"),
                        rs.getString("specialitecomplementaire"), rs.getString("id"), rs.getString("departement"));
                m.add(mm);
            }
            return m;

        } catch (Exception e) {
            System.out.println("Erreur dans le programme");
            e.printStackTrace();
        }
        return null;
    }

    public static Collection<Spe> getLesSpes() {
        try {
            Connection con = Connect.get();
            Statement req;
            req = con.createStatement();
            ResultSet rs = req.executeQuery("Select distinct specialitecomplementaire from medecin");
            Collection<Spe> s;
            s = new TreeSet<Spe>();
            while (rs.next()) {
                if (rs.getString("specialitecomplementaire") != null) {
                    Spe ss = new Spe(rs.getString("specialitecomplementaire"));

                    s.add(ss);
                }
            }
return s;
        } catch (Exception e) {
            System.out.println("Erreur dans le programme");
            e.printStackTrace();
        }
        return null;
    }
}
